
<template>
  <div :id="id" :class="className" :style="{height:height,width:width}" />
</template>

<script>
import resize from './mixins/resize'
export default {
  mixins: [resize],
  props: {
    id: {
      type: String,
      default: 'chart'
    },
    title: {
      type: String,
      default: '分布图'
    },
    subTitle: {
      type: String,
      default: ''
    },
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '100%'
    }
  },
  data() {
    return {
      // 配置
      // 状态
      // 数据
      chart: null
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      // 初始化
      this.chart = this.$echarts.init(document.getElementById(this.id))

      console.log(999, this.chart)
      // 数据
      // 配置
      this.chart.setOption({
        title: {
          text: this.title,
          subtext: this.subTitle,
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          type: 'scroll',
          orient: 'horizontal',
          bottom: 10,
          // data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
          align: 'auto'
          // selected: {
          //   1: true,
          //   2: true,
          //   3: false,
          //   4: false,
          //   5: true
          // }
        },
        series: [
          {
            name: '占比',
            type: 'pie',
            radius: '40%',
            center: ['50%', '50%'],
            label: {
              normal: {
                formatter: '{b}({d}%)',
                textStyle: {
                  fontSize: 12
                }
              }
            },
            data: [
              {
                name: 1,
                value: 1
              },
              {
                name: 2,
                value: 2
              },
              {
                name: 3,
                value: 3
              },
              {
                name: 4,
                value: 4
              },
              {
                name: 5,
                value: 5
              },
              {
                name: 6,
                value: 6
              },
              {
                name: 7,
                value: 7
              }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      })
    }

    /**
       * 数据组
       */
    /**
       * 按钮组
       */
    /**
       * 状态组
       */
    /**
       * 方法组
       */
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
  // .chart {
  // background-color: red;
  // }
</style>
